package com.lcy.config;

import com.zhipu.oapi.ClientV4;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
@ConfigurationProperties(prefix = "ai")
@Data
public class AiConfig {
    /*
    *apiKey需要从平台获取
    */
    private String apiKey;
    // 新增超时配置
    private int connectTimeout = 30; // 默认30秒
    private int readTimeout = 60;    // 默认60秒
    private int writeTimeout = 60;   // 默认60秒
    private int requestTimeout = 60; // 默认60秒

    @Bean
    public ClientV4 getClientV4(){

//        return new ClientV4.Builder(apiKey).build();
        return new ClientV4.Builder(apiKey)
                .networkConfig(
                        requestTimeout,
                        connectTimeout,
                        readTimeout,
                        writeTimeout,
                        TimeUnit.SECONDS
                )
                .build();
    }
}
